home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / programming / c / smc2cweb / src / c2cweb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-07  |  13.8 KB  |  1,092 lines

  1. #define banner "\nThis is c2cweb Version 1.4  (c) 1994 by Werner Lemberg\n\n" \
  2.  
  3. #define FALSE 0
  4. #define TRUE 1
  5. #define DONE 2
  6. #define WAIT 3 \
  7.  
  8. #define DIR_LENGTH 80
  9. #define TITLE_LENGTH 100
  10. #define PATH_SEPARATOR '/' \
  11.  
  12. #define FILE_NAME_LENGTH 80 \
  13.  
  14. #define BUFFER_LENGTH 500 \
  15.  
  16. #define xisspace(c) (isspace(c) &&((unsigned char) c<0200) )  \
  17.  
  18. /*4:*/
  19. #line 114 "c2cweb.w"
  20.  
  21. /*5:*/
  22. #line 194 "c2cweb.w"
  23.  
  24. #include <ctype.h>
  25. #include <getopt.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29.  
  30.  
  31. /*:5*/
  32. #line 115 "c2cweb.w"
  33. ;
  34. /*9:*/
  35. #line 326 "c2cweb.w"
  36.  
  37. void open_files(char*);
  38.  
  39. /*:9*//*12:*/
  40. #line 413 "c2cweb.w"
  41.  
  42. void handle_input(void);
  43.  
  44. /*:12*//*27:*/
  45. #line 1056 "c2cweb.w"
  46.  
  47. void usage(void);
  48.  
  49. /*:27*//*29:*/
  50. #line 1080 "c2cweb.w"
  51.  
  52. void modify_filename(char*);
  53.  
  54. /*:29*//*32:*/
  55. #line 1117 "c2cweb.w"
  56.  
  57. char*get_line(void);
  58.  
  59. /*:32*//*35:*/
  60. #line 1153 "c2cweb.w"
  61.  
  62. char*protect_underlines(char*);
  63.  
  64. /*:35*//*37:*/
  65. #line 1177 "c2cweb.w"
  66.  
  67. #ifndef __EMX__
  68. char*_getname(char*);
  69. #endif
  70.  
  71. /*:37*/
  72. #line 116 "c2cweb.w"
  73. ;
  74. /*6:*/
  75. #line 229 "c2cweb.w"
  76.  
  77. int tab_length= 4;
  78. int verbatim= FALSE;
  79. int user_linefeed= FALSE;
  80. int one_side= FALSE;
  81. char outdir[DIR_LENGTH+1];
  82. char title[TITLE_LENGTH+1];
  83.  
  84. #ifdef __EMX__
  85. char optchar[]= "-/";
  86. char pathsepchar[]= "\\/";
  87. #else
  88. char optchar[]= "-";
  89. char pathsepchar[]= "/";
  90. #endif
  91.  
  92. /*:6*//*8:*/
  93. #line 322 "c2cweb.w"
  94.  
  95. FILE*in,*out;
  96.  
  97. /*:8*//*13:*/
  98. #line 419 "c2cweb.w"
  99.  
  100. char buffer[BUFFER_LENGTH+1];
  101.  
  102. /*:13*//*31:*/
  103. #line 1112 "c2cweb.w"
  104.  
  105. int line_number= 0;
  106. int column;
  107.  
  108. /*:31*//*34:*/
  109. #line 1149 "c2cweb.w"
  110.  
  111. char tempbuf[2*FILE_NAME_LENGTH+1];
  112.  
  113. /*:34*/
  114. #line 117 "c2cweb.w"
  115. ;
  116.  
  117. void main(argc,argv)
  118. int argc;
  119. char*argv[];
  120.  
  121. {int i;
  122. char buffer[DIR_LENGTH+FILE_NAME_LENGTH+1];
  123. char*p,*q;
  124.  
  125.  
  126. printf(banner);
  127.  
  128. #ifdef __EMX__
  129. _response(&argc,&argv);
  130. _wildcard(&argc,&argv);
  131. #endif
  132.  
  133. /*7:*/
  134. #line 246 "c2cweb.w"
  135.  
  136. {char c;
  137. int i;
  138.  
  139.  
  140. outdir[0]= '\0';
  141. #ifdef __EMX__
  142. optswchar= optchar;
  143. #endif
  144.  
  145. strcpy(title,"c2cweb output");
  146.  
  147. while((c= getopt(argc,argv,"b:lo:t:v1"))!=EOF)
  148. {switch(c)
  149. {case'b':
  150. if(strchr(optchar,optarg[0]))
  151.  
  152. usage();
  153.  
  154. if(strlen(optarg)>=TITLE_LENGTH)
  155. fprintf(stderr,
  156. "\nTitle too long. Will use \"c2cweb output\".\n");
  157. else
  158. strcpy(title,optarg);
  159. break;
  160. case'l':
  161. user_linefeed= TRUE;
  162. break;
  163. case'o':
  164. if(strchr(optchar,optarg[0]))
  165. usage();
  166.  
  167. if((i= strlen(optarg))>=DIR_LENGTH)
  168. fprintf(stderr,
  169. "\nOutput directory name too long. Will be ignored.\n");
  170. else
  171. {strcpy(outdir,optarg);
  172. if(!strchr(pathsepchar,outdir[i-1]))
  173.  
  174. {outdir[i]= PATH_SEPARATOR;
  175. outdir[i+1]= '\0';
  176. }
  177. }
  178. break;
  179. case't':
  180. if(strchr(optchar,optarg[0]))
  181. usage();
  182.  
  183. tab_length= atoi(optarg);
  184. if(tab_length==0||tab_length>8)
  185. tab_length= 4;
  186. break;
  187. case'v':
  188. verbatim= TRUE;
  189. break;
  190. case'1':
  191. one_side= TRUE;
  192. break;
  193. default:
  194. usage();
  195. break;
  196. }
  197. }
  198. }
  199.  
  200. /*:7*/
  201. #line 135 "c2cweb.w"
  202. ;
  203.  
  204. if(optind==argc)
  205. usage();
  206.  
  207. for(i= optind;i<argc-1;i++)
  208. {printf("  processing %s\n",argv[i]);
  209.  
  210. open_files(argv[i]);
  211. q= protect_underlines(_getname(argv[i]));
  212. if((p= strrchr(q,'.'))!=NULL)
  213.  
  214.  
  215. fprintf(out,
  216. "@*{%s\\ZZZ{\\setbox0=\\hbox{%s}\\hskip-\\wd0}}.\n"
  217. "\\ind=2\n\n",q,p);
  218. else
  219. fprintf(out,"@*{%s}.\n"
  220. "\\ind=2\n\n",q);
  221.  
  222. handle_input();
  223. fclose(in);
  224. fclose(out);
  225. }
  226.  
  227. printf("  processing %s\n",argv[i]);
  228.  
  229. open_files(argv[i]);
  230. /*11:*/
  231. #line 373 "c2cweb.w"
  232.  
  233. fprintf(out,
  234. "\\font\\symb=cmsy10\n"
  235. "\\font\\math=cmmi10\n"
  236. "\\def\\ob"
  237. "{\\parskip=0pt\\parindent=0pt%%\n"
  238. "\\let\\\\=\\BS\\let\\{=\\LB\\let\\}=\\RB\\let\\~=\\TL%%\n"
  239. "\\let\\ =\\SP\\let\\_=\\UL\\let\\&=\\AM\\let\\^=\\CF%%\n"
  240. "\\obeyspaces\\frenchspacing\\tt}\n"
  241. "\n"
  242. "\\def\\e{\\hfill\\break\\hbox{}}\n"
  243. "\\def\\{{\\relax\\ifmmode\\lbrace\\else$\\lbrace$\\fi}\n"
  244. "\\def\\}{\\relax\\ifmmode\\rbrace\\else$\\rbrace$\\fi}\n"
  245. "\\def\\takenone#1{\\hskip-0.1em}\n"
  246. "\\let\\ZZZ=\\relax\n"
  247. "\n"
  248. "%s"
  249. "\n"
  250. "\\pageno=\\contentspagenumber \\advance\\pageno by 1\n"
  251. "\\let\\maybe=\\iftrue\n"
  252. "\n"
  253. "\\def\\title{%s}\n"
  254. "\n"
  255. "@i compiler.w\n"
  256. "\n",one_side?"\\let\\lheader=\\rheader\n":"",title);
  257.  
  258. for(i= optind;i<argc-1;i++)
  259. {strcpy(buffer,argv[i]);
  260. modify_filename(buffer);
  261.  
  262. fprintf(out,"@i %s\n",_getname(buffer));
  263. }
  264.  
  265. fputc('\n',out);
  266.  
  267.  
  268. /*:11*/
  269. #line 163 "c2cweb.w"
  270. ;
  271. q= protect_underlines(_getname(argv[i]));
  272. if((p= strrchr(q,'.'))!=NULL)
  273. fprintf(out,
  274. "@*{%s\\ZZZ{\\setbox0=\\hbox{%s}\\hskip-\\wd0}}.\n"
  275. "\\ind=2\n\n",q,p);
  276. else
  277. fprintf(out,"@*{%s}.\n"
  278. "\\ind=2\n\n",q);
  279.  
  280. handle_input();
  281. /*26:*/
  282. #line 1049 "c2cweb.w"
  283.  
  284. fprintf(out,
  285. "\n"
  286. "@*Index.\n"
  287. "\\let\\ZZZ=\\takenone\n");
  288.  
  289. /*:26*/
  290. #line 174 "c2cweb.w"
  291. ;
  292.  
  293. strcpy(buffer,argv[argc-1]);
  294. modify_filename(buffer);
  295.  
  296. printf(
  297. "\n You must now call CWEAVE with %s%s\n"
  298. " as the argument to get a TeX output",outdir,_getname(buffer));
  299. if(optind<argc-1)
  300. printf(" of all processed files");
  301. printf("\n");
  302.  
  303. fclose(in);
  304. fclose(out);
  305. }
  306.  
  307. /*:4*//*10:*/
  308. #line 330 "c2cweb.w"
  309.  
  310. void open_files(filename)
  311. char*filename;
  312. {char buffer[DIR_LENGTH+FILE_NAME_LENGTH+1];
  313.  
  314.  
  315. if(strlen(filename)>FILE_NAME_LENGTH-2)
  316. {fprintf(stderr,"\n  File name too long.\n");
  317. exit(-1);
  318. }
  319.  
  320. if((in= fopen(filename,"rt"))==NULL)
  321. {fprintf(stderr,"\n  Can't open input file %s\n",filename);
  322. exit(-1);
  323. }
  324.  
  325. strcpy(buffer,outdir);
  326. strcat(buffer,filename);
  327. modify_filename(buffer);
  328.  
  329. if((out= fopen(buffer,"wt"))==NULL)
  330. {fprintf(stderr,"\n  Can't open output file %s\n",buffer);
  331. exit(-1);
  332. }
  333. }
  334.  
  335.  
  336. /*:10*//*14:*/
  337. #line 425 "c2cweb.w"
  338.  
  339. void handle_input(void)
  340. {char*buf_p;
  341. char ch;
  342.  
  343. int any_input= FALSE;
  344.  
  345. int brace_count= 0;
  346. int blank_count= 0;
  347.  
  348. int in_comment= FALSE;
  349. int in_C= FALSE;
  350. int in_string= FALSE;
  351. int short_comment= FALSE;
  352. int leading_blanks= TRUE;
  353. int double_linefeed= FALSE;
  354. int linefeed_comment= FALSE;
  355.  
  356. int comment_slash= FALSE;
  357. int comment_star= FALSE;
  358. int escape_state= FALSE;
  359.  
  360. int before_TeX_text= FALSE;
  361.  
  362. int function_blocks= FALSE;
  363.  
  364.  
  365. line_number= 0;
  366.  
  367. while(get_line())
  368. {buf_p= buffer;
  369.  
  370. do
  371. {ch= *buf_p;
  372.  
  373. /*15:*/
  374. #line 539 "c2cweb.w"
  375.  
  376. if(buf_p==buffer)
  377. {if(!(in_comment||in_string))
  378. {if(!strncmp(buf_p,"/""*@@*""/",6))
  379. {in_C= FALSE;
  380. before_TeX_text= TRUE;
  381. function_blocks= WAIT;
  382. brace_count= 0;
  383.  
  384. if(any_input)
  385. fputs("\n@\n"
  386. "\\ind=2\n\n",out);
  387.  
  388. any_input= FALSE;
  389. *(buf_p--)= '\n';
  390.  
  391. goto end;
  392. }
  393. else if(!strncmp(buf_p,"/""*@*""/",5))
  394. {in_C= FALSE;
  395. before_TeX_text= TRUE;
  396. function_blocks= FALSE;
  397.  
  398. if(any_input)
  399. fputs("\n@\n"
  400. "\\ind=2\n\n",out);
  401.  
  402. any_input= FALSE;
  403. *(buf_p--)= '\n';
  404. goto end;
  405. }
  406. else if(!strncmp(buf_p,"/""*{*""/",5))
  407. {brace_count++;
  408. fputs("@{\n",out);
  409.  
  410. ch= '\n';
  411. goto end;
  412. }
  413. else if(!strncmp(buf_p,"/""*}*""/",5))
  414. {brace_count--;
  415. fputs("@}\n",out);
  416.  
  417. if(!brace_count&&function_blocks)
  418.  
  419. {in_C= FALSE;
  420. before_TeX_text= TRUE;
  421.  
  422. break;
  423. }
  424.  
  425. ch= '\n';
  426. goto end;
  427. }
  428. }
  429. }
  430.  
  431. if(double_linefeed&&ch=='/')
  432. linefeed_comment= TRUE;
  433.  
  434. if(double_linefeed&&(ch==' '||ch=='\t'))
  435. leading_blanks= TRUE;
  436.  
  437. if(ch!='\n')
  438. double_linefeed= FALSE;
  439.  
  440. if(!xisspace(ch))
  441. {any_input= TRUE;
  442.  
  443. if(before_TeX_text&&function_blocks)
  444. {before_TeX_text= FALSE;
  445.  
  446. if(function_blocks==WAIT)
  447. function_blocks= TRUE;
  448.  
  449. else
  450. {fputs("@\n"
  451. "\\ind=2\n\n",out);
  452.  
  453. if(leading_blanks)
  454. {leading_blanks= FALSE;
  455.  
  456. while(blank_count--)
  457. fputc(' ',out);
  458. blank_count= 0;
  459. }
  460. }
  461. }
  462.  
  463. if(in_comment&&leading_blanks)
  464. {leading_blanks= FALSE;
  465.  
  466. while(blank_count--)
  467. fputc(' ',out);
  468. blank_count= 0;
  469. }
  470. }
  471.  
  472. if(!(ch=='/'||xisspace(ch)))
  473.  
  474. {if(!(in_comment||in_C||comment_slash))
  475. {in_C= TRUE;
  476.  
  477. fputs("@c\n",out);
  478.  
  479. if(leading_blanks)
  480. {leading_blanks= FALSE;
  481.  
  482. while(blank_count--)
  483. fputc(' ',out);
  484. blank_count= 0;
  485. }
  486. }
  487.  
  488. if(!(in_comment||comment_slash)&&leading_blanks)
  489. {leading_blanks= FALSE;
  490.  
  491. while(blank_count--)
  492. fputc(' ',out);
  493. blank_count= 0;
  494. }
  495. }
  496.  
  497. if(comment_slash&&!(ch=='*'||ch=='/'))
  498.  
  499. {comment_slash= FALSE;
  500. if(!in_comment)
  501. linefeed_comment= FALSE;
  502.  
  503. fputc('/',out);
  504. }
  505.  
  506. if(comment_star&&ch!='/')
  507. {comment_star= FALSE;
  508.  
  509. fputc('*',out);
  510. }
  511.  
  512. if(escape_state&&!(ch=='\"'||ch=='\n'||ch=='\\'))
  513.  
  514. escape_state= FALSE;
  515.  
  516. /*:15*/
  517. #line 460 "c2cweb.w"
  518. ;
  519.  
  520. switch(ch)
  521. {case' ':
  522. if(leading_blanks)
  523. {blank_count++;
  524. goto end;
  525. }
  526. break;
  527.  
  528. case'\t':
  529. {int i= tab_length-(column%tab_length);
  530.  
  531. column+= i-1;
  532.  
  533. if(leading_blanks)
  534. {blank_count+= i;
  535. goto end;
  536. }
  537.  
  538. while(i--)
  539. fputc(' ',out);
  540. goto end;
  541. }
  542. break;
  543.  
  544. case'{':
  545. /*16:*/
  546. #line 681 "c2cweb.w"
  547.  
  548. if(in_comment)
  549. fputc('\\',out);
  550. else if(in_string)
  551. break;
  552. else if(function_blocks)
  553. {brace_count++;
  554. in_C= TRUE;
  555. }
  556.  
  557. /*:16*/
  558. #line 487 "c2cweb.w"
  559. ;
  560. break;
  561.  
  562. case'}':
  563. /*21:*/
  564. #line 727 "c2cweb.w"
  565.  
  566. if(in_comment)
  567. fputc('\\',out);
  568. else if(in_string)
  569. break;
  570. else if(function_blocks)
  571. {brace_count--;
  572. if(!brace_count)
  573. {in_C= FALSE;
  574.  
  575. before_TeX_text= TRUE;
  576. break;
  577. }
  578. }
  579.  
  580. /*:21*/
  581. #line 491 "c2cweb.w"
  582. ;
  583. break;
  584.  
  585. case'/':
  586. /*22:*/
  587. #line 743 "c2cweb.w"
  588.  
  589. if(comment_star)
  590. {comment_star= FALSE;
  591. leading_blanks= FALSE;
  592.  
  593. if(!short_comment)
  594. {in_comment= FALSE;
  595.  
  596. if(!in_C)
  597. {linefeed_comment= FALSE;
  598.  
  599. if(verbatim)
  600. fputs("*""/}",out);
  601.  
  602. if(*(buf_p+1)=='\n')
  603. fputs("\\e{}%",out);
  604.  
  605. goto end;
  606. }
  607.  
  608. if(in_C&&verbatim)
  609. {if(linefeed_comment)
  610. {linefeed_comment= FALSE;
  611.  
  612. fputs("*""/@>",out);
  613. if(*(buf_p+1)=='\n'&&!user_linefeed)
  614. fputs("@/",out);
  615. goto end;
  616. }
  617. else
  618. fputc('}',out);
  619. }
  620.  
  621. linefeed_comment= FALSE;
  622.  
  623. if(in_C||verbatim)
  624. fputc('*',out);
  625. else
  626. goto end;
  627. }
  628. else
  629. fputc('*',out);
  630. }
  631. else if(comment_slash)
  632. {comment_slash= FALSE;
  633.  
  634. if(!short_comment)
  635. {in_comment= TRUE;
  636. short_comment= TRUE;
  637.  
  638. if(!in_C&&verbatim)
  639. {fputs("{\\ob{}",out);
  640. if(leading_blanks)
  641. {leading_blanks= FALSE;
  642.  
  643. while(blank_count--)
  644. fputc(' ',out);
  645. blank_count= 0;
  646. }
  647. fputs("//",out);
  648.  
  649. goto end;
  650. }
  651.  
  652. if(in_C&&verbatim)
  653. {if(leading_blanks||linefeed_comment)
  654. {linefeed_comment= TRUE;
  655.  
  656. if(!user_linefeed)
  657. fputs("@/",out);
  658. fputs("@t}\\8{\\ob{}",out);
  659.  
  660.  
  661. if(leading_blanks)
  662. {leading_blanks= FALSE;
  663.  
  664. while(blank_count--)
  665. fputc(' ',out);
  666. blank_count= 0;
  667. }
  668. fputs("//",out);
  669. }
  670. else
  671. fputs("//{\\ob{}",out);
  672.  
  673. goto end;
  674. }
  675.  
  676. if(in_C||verbatim)
  677. fputc('/',out);
  678. else
  679. goto end;
  680. }
  681. else
  682. fputc('/',out);
  683. }
  684. else
  685. {comment_slash= TRUE;
  686.  
  687. goto end;
  688. }
  689.  
  690. /*:22*/
  691. #line 495 "c2cweb.w"
  692. ;
  693. break;
  694.  
  695. case'*':
  696. /*23:*/
  697. #line 846 "c2cweb.w"
  698.  
  699. if(comment_slash)
  700. {comment_slash= FALSE;
  701.  
  702. if(in_comment&&!short_comment)
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710. {fprintf(stderr,
  711. "    Error line %d: Nested comments not supported\n",
  712. line_number);
  713. exit(-1);
  714. }
  715.  
  716. if(!short_comment)
  717. {in_comment= TRUE;
  718.  
  719. if(!in_C&&verbatim)
  720. {fputs("{\\ob{}",out);
  721. if(leading_blanks)
  722. {leading_blanks= FALSE;
  723.  
  724. while(blank_count--)
  725. fputc(' ',out);
  726. blank_count= 0;
  727. }
  728. fputs("/""*",out);
  729.  
  730. goto end;
  731. }
  732.  
  733. if(in_C&&verbatim)
  734. {if(leading_blanks||linefeed_comment)
  735. {linefeed_comment= TRUE;
  736.  
  737. if(!user_linefeed)
  738. fputs("@/",out);
  739. fputs("@t}\\8{\\ob{}",out);
  740. if(leading_blanks)
  741. {leading_blanks= FALSE;
  742.  
  743. while(blank_count--)
  744. fputc(' ',out);
  745. blank_count= 0;
  746. }
  747. fputs("/""*",out);
  748. }
  749. else
  750. fputs("/""*{\\ob{}",out);
  751.  
  752. goto end;
  753. }
  754.  
  755. if(in_C||verbatim)
  756. fputc('/',out);
  757. else
  758. {fputs("  ",out);
  759.  
  760. goto end;
  761. }
  762. }
  763. else
  764. fputc('/',out);
  765. }
  766. else
  767. {comment_star= TRUE;
  768.  
  769. goto end;
  770. }
  771.  
  772. /*:23*/
  773. #line 499 "c2cweb.w"
  774. ;
  775. break;
  776.  
  777. case'\n':
  778. /*24:*/
  779. #line 921 "c2cweb.w"
  780.  
  781. blank_count= 0;
  782.  
  783. if(!in_comment&&in_C)
  784. {if(double_linefeed==FALSE)
  785. {double_linefeed= TRUE;
  786. if(escape_state)
  787. {escape_state= FALSE;
  788.  
  789. leading_blanks= TRUE;
  790.  
  791. if(in_string)
  792. fputc('\n',out);
  793. else
  794. fputs("\n@/",out);
  795. goto end;
  796. }
  797.  
  798. if(!leading_blanks&&user_linefeed)
  799. fputs("@/",out);
  800. }
  801. else if(double_linefeed==TRUE)
  802. {double_linefeed= DONE;
  803.  
  804.  
  805. fputs("@#",out);
  806. }
  807. }
  808.  
  809. leading_blanks= TRUE;
  810.  
  811. if(short_comment)
  812. {short_comment= FALSE;
  813. in_comment= FALSE;
  814. double_linefeed= TRUE;
  815.  
  816. if(verbatim)
  817. {if(linefeed_comment&&in_C)
  818. fputs("@>",out);
  819. else
  820. fputc('}',out);
  821. }
  822.  
  823. if(!in_C)
  824. fputs("\\e{}%",out);
  825. else if(linefeed_comment&&verbatim)
  826. fputs("@/",out);
  827.  
  828. linefeed_comment= FALSE;
  829. }
  830.  
  831. if(in_comment&&in_C&&verbatim&&linefeed_comment)
  832. {fputs("@>@/\n@t}\\8{\\ob{}",out);
  833.  
  834. goto end;
  835. }
  836.  
  837. if(in_comment&&verbatim)
  838.  
  839.  
  840.  
  841. {fputs("\n\\e{}",out);
  842. goto end;
  843. }
  844.  
  845. /*:24*/
  846. #line 503 "c2cweb.w"
  847. ;
  848. break;
  849.  
  850. case'@':
  851. /*17:*/
  852. #line 692 "c2cweb.w"
  853.  
  854. if(in_comment)
  855. {fputs("{\\char64}",out);
  856. goto end;
  857. }
  858. else
  859. fputc('@',out);
  860.  
  861. /*:17*/
  862. #line 507 "c2cweb.w"
  863. ;
  864. break;
  865.  
  866. case'\'':
  867. /*18:*/
  868. #line 701 "c2cweb.w"
  869.  
  870. if(!in_comment)
  871. {if(*(buf_p+1)=='\"'&&*(buf_p+2)=='\'')
  872. escape_state= TRUE;
  873. }
  874.  
  875. /*:18*/
  876. #line 511 "c2cweb.w"
  877. ;
  878. break;
  879.  
  880. case'\"':
  881. /*19:*/
  882. #line 708 "c2cweb.w"
  883.  
  884. if(!in_comment)
  885. {if(escape_state)
  886. escape_state= FALSE;
  887. else
  888. in_string= TRUE-in_string;
  889. }
  890.  
  891. /*:19*/
  892. #line 515 "c2cweb.w"
  893. ;
  894. break;
  895.  
  896. case'\\':
  897. /*20:*/
  898. #line 717 "c2cweb.w"
  899.  
  900. if(in_comment)
  901. {fputs("{\\symb\\char110}",out);
  902. goto end;
  903. }
  904. else
  905. escape_state= TRUE-escape_state;
  906.  
  907.  
  908. /*:20*/
  909. #line 519 "c2cweb.w"
  910. ;
  911. break;
  912.  
  913. default:
  914. /*25:*/
  915. #line 990 "c2cweb.w"
  916.  
  917. if(in_comment)
  918. {switch(ch)
  919. {case'#':
  920. fputs("{\\#}",out);
  921. break;
  922.  
  923. case'$':
  924. fputs("{\\$}",out);
  925. break;
  926.  
  927. case'%':
  928. fputs("{\\%}",out);
  929. break;
  930.  
  931. case'&':
  932. fputs("{\\AM}",out);
  933. break;
  934.  
  935. case'_':
  936. fputs("{\\_}",out);
  937. break;
  938.  
  939. case'^':
  940. fputs("{\\^{}}",out);
  941. break;
  942.  
  943. case'\\':
  944. fputs("{\\symb\\char110}",out);
  945. break;
  946.  
  947. case'~':
  948. fputs("{\\~{}}",out);
  949. break;
  950.  
  951. case'|':
  952. fputs("{\\symb\\char106}",out);
  953. break;
  954.  
  955. case'<':
  956. fputs("{\\math\\char60}",out);
  957. break;
  958.  
  959. case'>':
  960. fputs("{\\math\\char62}",out);
  961. break;
  962.  
  963. default:
  964. fputc(ch,out);
  965. break;
  966. }
  967.  
  968. goto end;
  969. }
  970.  
  971. /*:25*/
  972. #line 523 "c2cweb.w"
  973. ;
  974. break;
  975. }
  976.  
  977. fputc(ch,out);
  978.  
  979. end:
  980. buf_p++;
  981. column++;
  982. }while(ch!='\n');
  983. }
  984. }
  985.  
  986. /*:14*//*28:*/
  987. #line 1060 "c2cweb.w"
  988.  
  989. void usage(void)
  990. {fprintf(stderr,
  991. "Usage: c2cweb [switches] csourcefile(s) | @responsefile(s)"
  992. "\n"
  993. "\n  possible switches:"
  994. "\n"
  995. "\n    -b \"title\"    set title"
  996. "\n    -l            use input linefeeds"
  997. "\n    -o dirname    set output directory (must already exist)"
  998. "\n    -t tablength  set tabulator length (default 4)"
  999. "\n    -v            verbatim mode"
  1000. "\n    -1            one-sided output"
  1001. "\n"
  1002. "\n");
  1003.  
  1004. exit(-1);
  1005. }
  1006.  
  1007. /*:28*//*30:*/
  1008. #line 1088 "c2cweb.w"
  1009.  
  1010. void modify_filename(name)
  1011. char*name;
  1012. {char*p;
  1013.  
  1014.  
  1015. if((p= strrchr(name,'.'))!=NULL)
  1016. {p++;
  1017. if(*p&&*p!=' ')
  1018. p++;
  1019. if(*p&&*p!=' ')
  1020. p++;
  1021. if(*p!='w')
  1022. *p= 'w';
  1023. else
  1024. *p= 'x';
  1025. p++;
  1026. *p= '\0';
  1027. }
  1028. else
  1029. strcat(name,".w");
  1030. }
  1031.  
  1032. /*:30*//*33:*/
  1033. #line 1123 "c2cweb.w"
  1034.  
  1035. char*get_line(void)
  1036. {char*p;
  1037. int i= BUFFER_LENGTH;
  1038.  
  1039.  
  1040. if((p= fgets(buffer,BUFFER_LENGTH+1,in))!=NULL)
  1041. {while(i--)
  1042. {if(*(p++)=='\n')
  1043. break;
  1044. }
  1045.  
  1046. p--;
  1047. p--;
  1048. while((*p==' '||*p=='\t')&&p>=buffer)
  1049. p--;
  1050. *(p+1)= '\n';
  1051. *(p+2)= '\0';
  1052.  
  1053. line_number++;
  1054. column= 0;
  1055. }
  1056. return(p);
  1057. }
  1058.  
  1059. /*:33*//*36:*/
  1060. #line 1159 "c2cweb.w"
  1061.  
  1062. char*protect_underlines(p)
  1063. char*p;
  1064. {char*q;
  1065.  
  1066.  
  1067. q= tempbuf;
  1068.  
  1069. do
  1070. {if(*p=='_')
  1071. *(q++)= '\\';
  1072. *(q++)= *p;
  1073. }while(*(p++));
  1074.  
  1075. return tempbuf;
  1076. }
  1077.  
  1078. /*:36*//*38:*/
  1079. #line 1186 "c2cweb.w"
  1080.  
  1081. #ifndef __EMX__
  1082. char*_getname(char*path)
  1083. {char*p;
  1084.  
  1085. p= strrchr(path,'/');
  1086. return p==NULL?path:(p+1);
  1087. }
  1088. #endif
  1089.  
  1090.  
  1091. /*:38*/
  1092.